package com.atguigu.gulimall.search.thread;

import java.util.concurrent.*;

/**
 * 线程池测试
 *
 * @author LaiSanShan
 * @date 2021-08-16
 */
public class ThreadPoolTest {

    public static void main(String[] args) {
        newThreadPoolExecutor();
    }

    /**
     * 原生创建线程池
     */
    private static void newThreadPoolExecutor() {
        //allowCoreThreadTimeOut
        // 核心线程数
        int corePoolSize = 10;
        // 最大线程数
        int maximumPoolSize = 20;
        // 非核心线程最大存活时间
        long keepAliveTime = 30;
        // 时间单位
        TimeUnit unit = TimeUnit.SECONDS;
        // 阻塞队列
        BlockingQueue<Runnable> workQueue = new LinkedBlockingDeque<>(10);
        // 线程工厂
        ThreadFactory threadFactory = Executors.defaultThreadFactory();
        // 拒绝策略
        RejectedExecutionHandler handler = new ThreadPoolExecutor.DiscardPolicy();

        // 原生创建线程池
        new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
    }

}
